import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react';

import {
    Button,
    DatePicker,
    Form,
    Input,
    Modal,
    Radio,
    Tag,
    Select,
    InputNumber,
    message,
    Row,
    Col,
} from 'antd';
import { modalLayoutLg, modalLayoutSm } from '@/config/layout';
import { request } from 'umi';
const DictModal = (props: any, refs: any) => {
    const [form] = Form.useForm();
    // const [fileList,setfileList] = useState([]);
    const [measureClassData, setmeasureClassData] = useState([]);
    const { setFieldsValue, resetFields } = form;
    const [videosrc, setvideosrc] = useState('');
    const [code, setCode] = useState('');
    const [isModalVisible, setIsModalVisible] = useState(false);
    const { TextArea } = Input;
    //显示弹窗
    const showModal = () => {
        setIsModalVisible(true);
    };

    //取消
    const handleCancel = () => {
        setIsModalVisible(false);
        setCode('');
        setvideosrc('');
        resetFields();
        props.callback && props.callback();
    };

    const getDetail = (id: any) => {
        request('/plan/work-achievement-upload/queryById?id=' + id, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
            },
            data: {
                id,
            },
        }).then((res) => {
            setvideosrc(res?.data?.url)
            showModal();
        });
    };
    useImperativeHandle(refs, () => ({
        init: (id: any, record: any) => {
            setCode(id);
            getDetail(id);
            // setfileList([]);
        },
    }));

    return (
        <Modal
            title={'帮助'}
            visible={isModalVisible}
            onCancel={handleCancel}
            centered
            width={1000}
            height={window.innerHeight - 150}
            maskClosable={false}
            destroyOnClose
            footer={<Button onClick={handleCancel}>关闭</Button>}
            bodyStyle={{
                height: '600px',
                overflowY: 'auto',
            }}
        >
            {
                videosrc && <video autoPlay style={{ width: '100%', height: '100%' }} controls src={videosrc}></video>
            }
        </Modal>
    );
};
const AddMCom = forwardRef(DictModal);

export default AddMCom;
